package com.shinemo.mpush.alloc.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;
import com.mpush.tools.common.HashUtil;
import com.mpush.tools.config.CC;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class HttpBodyUtils {

	private HttpBodyUtils() {
	}

	public static List<NameValuePair> convert(Map<String, String> params) {

		List<NameValuePair> list = new ArrayList<>(0);

		params.entrySet().forEach(entry -> list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())));

		return list;
	}

	public static String getQueryString(Map<String, String> params){
		return Lists.newArrayList(params.keySet()).stream().filter(Objects::nonNull).sorted()
				.map(key -> String.join("=", key, params.get(key))).collect(Collectors.joining("&"));
	}

}
